<?

$ClientID = $_GET['ClientID'];

function getNoOfVisits($ClientID)
{
	$queryNoOfVisits = "SELECT er_Client.client_id, COUNT(er_visit.visit_id)
						FROM er_Client, er_visit
						WHERE er_Client.client_id=er_visit.client_id
						AND er_visit.visit_date >= DATE_SUB(NOW(), INTERVAL 1 YEAR)
						AND er_Client.client_id='$ClientID'
						GROUP BY er_Client.client_id";
	$resultNoOfVisits = r_db($queryNoOfVisits);
	$rowNoOfVisits = mysql_fetch_array($resultNoOfVisits);
	$noOfVisits = $rowNoOfVisits[1];
	return $noOfVisits;
}

function make_income_html($arr, $num, $width, $name,$name1,$name2)
{
	echo   "<tr>\n";
	echo   "<td>Income Type</td>";
	echo   "<td>Amount</td>";
	echo   "<td>When Due</td>";
	echo   "</tr>\n";
	for ($i=1; $i<=3; $i++)
	{
		echo   "<tr><td>";
		echo "<select name=\"$name\">";
		echo "<option>Select Client Income</option>";
		$query="SELECT * FROM er_income_source ORDER BY income_type" ;
		$results=r_db($query);
		while ($row=mysql_fetch_array($results))
		{
			if ($row[1]!="Other" && $row[1]!="Select Client Income")
			echo "<option>$row[1]</option>";
		}
		echo "<option>Other</option>";
		echo   "<td><input type=\"text\" name=\"$name1\" value=\"0.00\" onchange=\"return checkbandollar(this)\" ></td>\n";
		echo   "<td><input type=\"text\" name=\"$name2\" size='10' maxlength=\"10\"  onKeyUp=\"DateFormat(this,this.value,event,false,'3')\" onBlur=\"DateFormat(this,this.value,event,true,'3')\" onchange=\"DatePosition(this.value,3)\"></td>\n";
		echo   "</tr>\n";
	}
}

function make_html($incomes_source, $client_income, $num, $width, $name,$name1,$name2)
	{

		echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n";
		echo "<tr>\n";
		echo  "<td>Income Type</td>";
		echo "<td>Amount</td>";
		echo "<td>When Due</td>";
		echo  "</tr>";

		foreach ($client_income as $entry)
		{
			echo "<tr>";
			echo "<td>";
			$rowIncomeType = getFieldsFromLookUpTable("er_income_source","income_id",$entry->income_id);
			echo "<select name=$name>";
			$query="SELECT * FROM er_income_source ORDER BY income_type";

			$results=r_db($query);

			if($rowIncomeType[1]=="Select Client Income")
				echo "<option selected>Select Client Income</option>";
			else
				echo "<option>Select Client Income</option>";

			while ($row=mysql_fetch_array($results))
			{
				if ($row[1]!="Other" && $row[1]!="Select Client Income")
				{
					if($row[1]==$rowIncomeType[1])
						echo "<option selected>$row[1]</option>";
					else
						echo "<option>$row[1]</option>";
				}

			}
			if($rowIncomeType[1]=="Other")
				echo "<option selected>Other</option>";
			else
				echo "<option>Other</option>";

			echo "</select>";
			echo "</td>";
			echo  "<td><input type=\"text\" name=\"$name1\" value=\"$entry->income_amount\"></td>\n";

			$DbDOB=explode("-",$entry->when_due);

					$dayDOB=$DbDOB[2];

					$monthDOB=$DbDOB[1];

					$yearDOB=$DbDOB[0];

					$DueDB=$dayDOB."/".$monthDOB."/".$yearDOB;

			echo "<td><input type=\"text\" 
						name=\"whenDue[]\" 
						value=\"$DueDB\"
						size=\"10\" 
						maxlength=\"10\">&nbsp;<img alt=\"Date Picker\" onclick=\"new CalendarDateSelect( $(this).previous(), {year_range:10} );\" src=\"images/calendar.gif\" style=\"border:0px; cursor:pointer;\" />
					<br>DD/MM/YYYY or empty
				  </td>";
			echo "</tr>";

		}


	}



function make_er_checkbox_html($arr, $num, $width, $name, $checked)
{
	$closingTR = false;
	$str = "";
	$str .= "<tr>\n";
	if (count($arr) % $num != 0)
	{
		$closingTR = true;
	}

	$i=1;

	$str = "";
	$str .= "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">\n";
	$str .= "<tr>\n";

	if (isset($checked))
	{
		//    /* if we passed in an array of the checkboxes we want
		//       to be displayed as checked */
		foreach ($arr as $ele)
		{
			$str .= "<td><input type=\"checkbox\" name=\"$name\" value=\"$ele->er_id\"";
			foreach ($checked as $entry)
			{
				if ($entry->relief_id == $ele->er_id)
				{
					$str .= "checked";
					continue;//skip rest of current loop, continue execution at beginning of the next iteration
				}
			}
			$str .= ">";
			$str .= "$ele->er_reason\n</td>";
			if ($i % $num == 0)
			{
				$str .= "</tr>\n<tr>";
			}
			else
			{
				$str .= "</td>\n";
			}
			$i++;


		}
	}
	return $str;
}


      function make_actions_checkbox_html($arr, $num, $width, $name, $checked)
      {
      	$closingTR = false;
		global $rowVisit;
      	$str = "";
      	$str .= "<tr>\n";
      	if (count($arr) % $num != 0)
      	{
      		$closingTR = true;
      	}

      	$i=1;
		if (isset($checked))
		{
	      	foreach ($arr as $ele)
	      	{
	      		$str .= "<td><input type=\"checkbox\" name=\"$name\" value=\"$ele->action_id\"";
				foreach ($checked as $entry)
				{
					if ($entry->action_id == $ele->action_id)
					{
						$str .= "checked";
						continue;//skip rest of current loop, continue execution at beginning of the next iteration
					}
				}
				$str .= ">";
				$str .= "$ele->action_taken\n</td>";
	      		if($ele->action_taken=="Discussed Return Date(if no entitlement or not eligible)")
	      		{
						$str = substr($str,0,strlen($str)-5);
	        			$str .= "<br /><span style=\"padding-left:20px;\">Return date: <input 	type=\"text\" 
												id=\"txtReturnDate\"
												name=\"txtReturnDate\" 
												size=\"10\" 
												maxlength=\"10\" 
												value=\"".$rowVisit['return_date']."\"
												onchange=\"javascript:checkDate(this,4);\">&nbsp;
												<img alt=\"Date Picker\" onclick=\"new CalendarDateSelect( $(this).previous(), {year_range:10} );\" src=\"./images/calendar.gif\" style=\"border:0px; cursor:pointer;\" />
												DD/MM/YYYY or empty</span></td>";
	      		}
				if ($i % $num == 0)
				{
					$str .= "</tr>\n<tr>";
				}
				else
				{
					$str .= "</td>\n";
				}
				$i++;
	      		if($ele->action_taken=="Other")
	      		{
	      			$str .= "<td>Other Reason (financial only):</td>";
	      			$str .= "<td><input type=\"text\" name=\"txtActionOther\" size=\"20\" maxlength=\"50\" value=\"".$rowVisit['action_taken']."\"></td>";
	      		}
	      	}
      	return $str;
		}
      }


function getselectedVisitDetails($VisitID)
{
	$queryVisitDate = "SELECT

						  er_visit.*,
						  er_housing_type.housing_type,
						  er_income_status.income_status_type,
						  er_agency.agency_name
						  FROM er_visit,er_housing_type,er_income_status,er_agency
						  WHERE er_visit.housing_type_id=er_housing_type.housing_type_id
						  AND er_visit.income_status_id=er_income_status.income_status_id
						  AND er_visit.agency_id=er_agency.agency_id
						  AND er_visit.visit_id=$VisitID";

	$resultVisit = r_db($queryVisitDate);
	return $resultVisit;

}

?>
<html>
<head>
<head>
<link rel="stylesheet" type="text/css" href="CSS.css">
<script language="JavaScript">
function DatePosition(dateString,value) {
    var now = new Date();
    var today = new Date(now.getYear(),now.getMonth(),now.getDate());
    var century = parseInt(now.getYear()/100)*100;
		var date = new Date(dateString.substring(6,10),
                            dateString.substring(3,5)-1,
                            dateString.substring(0,2));

	if(value == 1)
	{
  if (Date.parse(date) > Date.parse(today))
	    {
	      alert('Visit date must be less than or equal to todays date.');
	      document.form.txtVisitDate.select();
	      document.form.txtVisitDate.focus();
	    }
	}

	if(value == 2)
	{
  if (Date.parse(date) >= Date.parse(today))
	    {
	      alert('Birth Date must be less than todays date.');
	      document.form.txtDateOfBirth.select();
	      document.form.txtDateOfBirth.focus();
	    }
	}

	if(value == 3)
	{
  if (Date.parse(date) < Date.parse(today))
	    {
	      alert('When Due date must be greater than or equal to todays date.');
	      return -1;
	    }
	}
}

function convertcurrentcy1 (num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function convertcurrency (i) {
 var result = parseFloat(i.value)
 if (i.value == 0 || i.value == NULL) {
  result = '0.00'
 }
 else {
  result = result.toFixed(2)
  result = result.toString()
  var decimal_location = result.indexOf(".")
  var decimal_part_length = result.length - decimal_location - 1
  var pad_total = 2 - decimal_part_length
  if (pad_total > 0) {
		for (var counter = 1; counter <= pad_total; counter++) {
        result += "0"
		}
  }
 }
 i.value = result
}

<!--dollar value-->
function parseelement(thisone){
	var prefix="$"
var wd
	if (thisone.value.charAt(0)=="$")
		return thisone
	wd="w"
	var tempnum=thisone.value
	for (i=0;i<tempnum.length;i++){
		if (tempnum.charAt(i)=="."){
			wd="d"
			break
		}
	}
	if (wd=="w")
		thisone.value=tempnum+".00"
	else{
		if (tempnum.charAt(tempnum.length-2)==".") {
			thisone.value=tempnum+"0"
		}
		else {
			tempnum=Math.round(tempnum*100)/100
			thisone.value=tempnum
		}
	}
}

function checknumber(pnum){
	var x=pnum.value
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(x))
	{
		testresult=true
	}
	else{
		alert("Please input a valid number!")
		testresult=false
	}
	return (testresult)
}

function checkban(pnum){
	if (document.layers||document.all||document.getElementById)
		return checknumber(pnum)
	else
		return true
}

function checknumberdollar(pnum){
	var x=pnum.value
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(x))
	{
		parseelement(pnum)
		testresult=true
	}
	else{
		alert("Please input a valid number!")
		testresult=false
	}
	return (testresult)
}


function checkbandollar(pnum){
	if (document.layers||document.all||document.getElementById)
		return checknumberdollar(pnum)
	else
		return true
}

<!--make the initial alphabet uppercase-->
function changeCase(frmObj) {
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = frmObj.value.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)  {
		for (index = 0; index < strLen; index++)  {
			if (index == 0)  {
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,strLen);
				tmpStr = tmpChar + postString;
			}
			else {
				tmpChar = tmpStr.substring(index, index+1);
				if (tmpChar == " " && index < (strLen-1))  {
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);
					postString = tmpStr.substring(index+2,strLen);
					tmpStr = preString + tmpChar + postString;
	      }
	    }
		}
	}
	frmObj.value = tmpStr;
}

<!--element focus-->
function putFocus(formInst, elementInst) {
	if (document.forms.length > 0) {
  	document.forms[formInst].elements[elementInst].focus();
  }
}

<!--help provider-------->
function explain(name,output,msg) {
	newwin = window.open('','','top=150,left=150,width=325,height=300');
	if (!newwin.opener)
		newwin.opener = self;
	with (newwin.document)
	{
	open();
	write('<html>');
	write('<body onLoad="document.form.box.focus()" background="./images/10/main.jpg"><form name=form >' + msg + '<br>');
	write('<p>You may enter your ' + name + ' here and it will be copied into the form for you.');
	write('<p><center>' + name + ':  <input type=text name=box size=10 onKeyUp=' + output + '=this.value>');
	write('<p><input type=button value="Click to close when finished" onClick=window.close()>');
	write('</center></form></body></html>');
	close();
  }
}

<!-----------------------Validation OF Date---------------------------------------------------------->
var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/";
// If you are using any Java validation on the back side you will want to use the / because
// Java date validations do not recognize the dash as a valid date separator.
var vDateType = 3; // Global value for type of date format
//                1 = mm/dd/yyyy
//                2 = yyyy/dd/mm  (Unable to do date check at this time)
//                3 = dd/mm/yyyy
var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.
var err = 0; // Set the error code to a default of zero
if(navigator.appName == "Netscape") {
if (navigator.appVersion < "5") {
isNav4 = true;
isNav5 = false;
}
else
if (navigator.appVersion > "4") {
isNav4 = false;
isNav5 = true;
   }
}
else {
isIE4 = true;
}

function DateFormat(vDateName, vDateValue, e, dateCheck, dateType) {
vDateType = dateType;
// vDateName = object name
// vDateValue = value in the field being checked
// e = event
// dateCheck
// True  = Verify that the vDateValue is a valid date
// False = Format values being entered into vDateValue only
// vDateType
// 1 = mm/dd/yyyy
// 2 = yyyy/mm/dd
// 3 = dd/mm/yyyy
//Enter a tilde sign for the first number and you can check the variable information.
if (vDateValue == "~") {
alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);
vDateName.value = "";
vDateName.focus();
return true;
}
var whichCode = (window.Event) ? e.which : e.keyCode;
// Check to see if a seperator is already present.
// bypass the date if a seperator is present and the length greater than 8
if (vDateValue.length > 8 && isNav4) {
if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
return true;
}
//Eliminate all the ASCII codes that are not valid
var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
if (alphaCheck.indexOf(vDateValue) >= 1) {
if (isNav4) {
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
else {
vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
return false;
   }
}
if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
return false;
else {
//Create numeric string values for 0123456789/
//The codes provided include both keyboard and keypad values
var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
if (strCheck.indexOf(whichCode) != -1) {
if (isNav4) {
if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1)) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
if (vDateValue.length == 6 && dateCheck) {
var mDay = vDateName.value.substr(2,2);
var mMonth = vDateName.value.substr(0,2);
var mYear = vDateName.value.substr(4,4)
//Turn a two digit year into a 4 digit year
if (mYear.length == 2 && vYearType == 4) {
var mToday = new Date();
//If the year is greater than 30 years from now use 19, otherwise use 20
var checkYear = mToday.getFullYear() + 30;
var mCheckYear = '20' + mYear;
if (mCheckYear >= checkYear)
mYear = '19' + mYear;
else
mYear = '20' + mYear;
}
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (!dateValid(vDateValueCheck)) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
return true;
}
else {
// Reformat the date for validation and set date type to a 1
if (vDateValue.length >= 8  && dateCheck) {
if (vDateType == 1) // mmddyyyy
{
var mDay = vDateName.value.substr(2,2);
var mMonth = vDateName.value.substr(0,2);
var mYear = vDateName.value.substr(4,4)
vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
}
if (vDateType == 2) // yyyymmdd
{
var mYear = vDateName.value.substr(0,4)
var mMonth = vDateName.value.substr(4,2);
var mDay = vDateName.value.substr(6,2);
vDateName.value = mYear+strSeperator+mMonth+strSeperator+mDay;
}
if (vDateType == 3) // ddmmyyyy
{
var mMonth = vDateName.value.substr(2,2);
var mDay = vDateName.value.substr(0,2);
var mYear = vDateName.value.substr(4,4)
vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
}
//Create a temporary variable for storing the DateType and change
//the DateType to a 1 for validation.
var vDateTypeTemp = vDateType;
vDateType = 1;
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (!dateValid(vDateValueCheck)) {
alert("Invalid Date\nPlease Re-Enter");
vDateType = vDateTypeTemp;
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
vDateType = vDateTypeTemp;
return true;
}
else {
if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
         }
      }
   }
}
else {
// Non isNav Check
if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
return true;
}
// Reformat date to format that can be validated. mm/dd/yyyy
if (vDateValue.length >= 8 && dateCheck) {
// Additional date formats can be entered here and parsed out to
// a valid date format that the validation routine will recognize.
if (vDateType == 1) // mm/dd/yyyy
{
var mMonth = vDateName.value.substr(0,2);
var mDay = vDateName.value.substr(3,2);
var mYear = vDateName.value.substr(6,4)
}
if (vDateType == 2) // yyyy/mm/dd
{
var mYear = vDateName.value.substr(0,4)
var mMonth = vDateName.value.substr(5,2);
var mDay = vDateName.value.substr(8,2);
}
if (vDateType == 3) // dd/mm/yyyy
{
var mDay = vDateName.value.substr(0,2);
var mMonth = vDateName.value.substr(3,2);
var mYear = vDateName.value.substr(6,4)
}
if (vYearLength == 4) {
if (mYear.length < 4) {
alert("Invalid Date\nPlease Re-Enter");
vDateName.value = "";
vDateName.focus();
return true;
   }
}
// Create temp. variable for storing the current vDateType
var vDateTypeTemp = vDateType;
// Change vDateType to a 1 for standard date format for validation
// Type will be changed back when validation is completed.
vDateType = 1;
// Store reformatted date to new variable for validation.
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (mYear.length == 2 && vYearType == 4 && dateCheck) {
//Turn a two digit year into a 4 digit year
var mToday = new Date();
//If the year is greater than 30 years from now use 19, otherwise use 20
var checkYear = mToday.getFullYear() + 30;
var mCheckYear = '20' + mYear;
if (mCheckYear >= checkYear)
mYear = '19' + mYear;
else
mYear = '20' + mYear;
vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
// Store the new value back to the field.  This function will
// not work with date type of 2 since the year is entered first.
if (vDateTypeTemp == 1) // mm/dd/yyyy
vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
if (vDateTypeTemp == 3) // dd/mm/yyyy
vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
}
if (!dateValid(vDateValueCheck)) {
alert("Invalid Date\nPlease Re-Enter");
vDateType = vDateTypeTemp;
vDateName.value = "";
vDateName.focus();
return true;
}
vDateType = vDateTypeTemp;
return true;
}
else {
if (vDateType == 1) {
if (vDateValue.length == 2) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 5) {
vDateName.value = vDateValue+strSeperator;
   }
}
if (vDateType == 2) {
if (vDateValue.length == 4) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 7) {
vDateName.value = vDateValue+strSeperator;
   }
}
if (vDateType == 3) {
if (vDateValue.length == 2) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 5) {
vDateName.value = vDateValue+strSeperator;
   }
}
return true;
   }
}
if (vDateValue.length == 10&& dateCheck) {
if (!dateValid(vDateName)) {
// Un-comment the next line of code for debugging the dateValid() function error messages
//alert(err);
alert("Invalid Date\nPlease Re-Enter");
vDateName.focus();
vDateName.select();
   }
}
return false;
}
else {
// If the value is not in the string return the string minus the last
// key entered.
if (isNav4) {
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
else
{
vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
return false;
         }
      }
   }
}

function dateValid(objName) {
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
// var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
//strDate = datefield.value;
strDate = objName;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
//Adjustment for short years entered
if (strYear.length == 2) {
strYear = '20' + strYear;
}
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
   }
}
else {
if (intday > 28) {
err = 10;
return false;
      }
   }
}
return true;
}

function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

<!----verify if everything has been inputed---->
function verify() {
	var themessage = "You are required to complete the following fields: \n";
	if (document.form.txtCurrentAddress.value=="") {
		themessage = themessage + " - Address\n";
	}
	if (document.form.txtCurrentSuburb.value=="") {
		themessage = themessage + " - Suburb\n";
	}
	if (document.form.txtCurrentPostCode.value=="") {
		themessage = themessage + " - Post Code\n";
	}
	if (document.form.txtVisitDate.value=="") {
		themessage = themessage + " - Visit Date\n";
	}
	if (checkToggle('form','emergencyReliefs[]') == false) {
		themessage = themessage + " - At least 1 reason for seeking assistance\n";
	}

	if (checkToggle('form','actionTaken[]') == false) {
		themessage = themessage + " - At least 1 Action taken associated with ER\n";
	}
	if (document.form.txtInterviewer.value=="") {
		themessage = themessage + " - Interviewer\n";
	}
	if (document.form.txtAdults.value==0 && document.form.txtChildren.value==0) {
		themessage = themessage + " \n Please Note:\n Both Number of Adults and children can't be zero\n";
	}
	if (themessage == "You are required to complete the following fields: \n") {
		document.form.btnSaveForm.disabled=true;
		document.form.btnSaveForm.value='Please wait...';
		document.form.submit();
	}
	else {
		alert(themessage);
		return false;
	}
}

//script to check that atleast one checkbox for reason for seekign assistance has been checked
function checkToggle (theForm,theCheckbox) {
    // Set target elements
    var theElements = document.forms[theForm].elements[theCheckbox];
   // Loop through the elements


   var check = 0;
    for (var count = 0; count < theElements.length; count++)
    {

         if(theElements[count].checked == true)
         {
         	check++;
         }
    }

    if(check >0)
    {
    	return true;
    }
    else
    {
    	return false;
    }
}


function disableassistance(theForm,theCheckbox) {

    var theElements = document.forms[theForm].elements[theCheckbox];

   var check = 0;
    for (var count = 0; count < theElements.length; count++)
    {
    	if(theElements[count].value == '0' || theElements[count].value == '0.00')
    	{
       		//theElements[count].disabled = true;
       		//check =0;
    	}
    	else
    	{
    		//alert(' Please make sure that dollar amounts for all types of assistance is zero');
    		check ++;
    	}
    }

    if(check > 0)
    {
    	alert(' Please make sure that dollar amounts for all types of assistance is zero');
    }
    else
    {
    	for (var count = 0; count < theElements.length; count++)
    	{
    		theElements[count].disabled = true;
    	}

    	document.form.txtChequePayee.disabled = true;
    	document.form.txtErAmountRecieptNo.disabled = true;
    	document.form.txtReasonChequePayment.disabled = true;
    	document.form.txtOtherPaymentType.disabled = true;
    }

}


function enableassistance(theForm,theCheckbox) {
    // Set target elements
    var theElements = document.forms[theForm].elements[theCheckbox];
   // Loop through the elements


   var check = 0;


    for (var count = 0; count < theElements.length; count++)
    {

       theElements[count].disabled = false;


    }
   	  document.form.txtChequePayee.disabled = false;
    	document.form.txtErAmountRecieptNo.disabled = false;
    	document.form.txtReasonChequePayment.disabled = false;
    	document.form.txtOtherPaymentType.disabled = false;

}

<!------ to remove the white spaces------>
function remove_XS_whitespace(item)
{
 item.value = item.value.replace(/\r/g, " ");
  item.value = item.value.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");
  //item.value = item.value.replace(/'/g, "");
  item.value = item.value.replace(/ +/g, " ");
  item.value = item.value.replace(/^\s/g, "");
  item.value = item.value.replace(/\s$/g, "");
  if (item.value == ' '){item.value = ''};
}

<!----checks if only aplhabets are included in fields such as name-->
function checkalpha(item)
{
var i=0;
for(i=0;i<=item.length-1;i++)
{
	if(!isAlpha(item.substring(i,i+1)))
	{
	alert('only aphabets please');
	return false;
	}
	else
	{
	return true;
	}
}

}

<!---- the following scripts is for acquiring the other types of different combo boxes.---->
function otherhousingtype(sel)
{
	option=document.form.cmbHousingType.options[document.form.cmbHousingType.selectedIndex].text;
	txt=option;

	if(txt == 'Other')
	{
		message='Enter Other Housing type here';
		document.form.txtOtherHousingType.value=message;
		document.form.txtOtherHousingType.select();
		document.form.txtOtherHousingType.focus();
	}
	else
	{
		document.form.txtOtherHousingType.value="";
		document.form.cmbHousingType.focus();
	}
}

function otherhousingtypenull(sel)
{

	option=document.form.cmbHousingType.options[document.form.cmbHousingType.selectedIndex].text;
	txt=option;
	option1=document.form.txtOtherHousingType.value;
	txt1=option1;

	if(txt == 'Other' && txt1 == "Enter Other Housing type here")
	{
		if(!confirm('Are you sure NOT to enter other Housing type?'))
		{
			document.form.txtOtherHousingType.select();
			document.form.txtOtherHousingType.focus();
		}
		else
		{
			document.form.txtOtherHousingType.value="";

		}
	}
}

function otherincomestatus(sel)
{
	option=document.form.cmbIncomeStatus.options[document.form.cmbIncomeStatus.selectedIndex].text;
	txt=option;

	if(txt == 'Other')
	{
		message='Enter Other Income Status type here';
		document.form.txtOtherIncomeStatusType.value=message;
		document.form.txtOtherIncomeStatusType.select();
		document.form.txtOtherIncomeStatusType.focus();
	}
	else
	{
		document.form.txtOtherIncomeStatusType.value="";
		document.form.cmbIncomeStatus.focus();
	}

}

function otherincomestatusnull(sel)
{
	option=document.form.cmbIncomeStatus.options[document.form.cmbIncomeStatus.selectedIndex].text;
	txt=option;
	option1=document.form.txtOtherIncomeStatusType.value;
	txt1=option1;

	if(txt == 'Other' && txt1 == "Enter Other Income Status type here")
	{
		if(!confirm('Are you sure NOT to enter other Income type?'))
		{
			document.form.txtOtherIncomeStatusType.select();
			document.form.txtOtherIncomeStatusType.focus();
		}
		else
		{
			document.form.txtOtherIncomeStatusType.value="";

		}
	}
	else
	{

	}

}

function otheridtype(sel)
{
	option=document.form.cmbIdType.options[document.form.cmbIdType.selectedIndex].text;
	txt=option;

	if(txt == 'Other')
	{
		message='Enter Other ID type here';
		document.form.txtOtherIdType.value=message;
		document.form.txtOtherIdType.select();
		document.form.txtOtherIdType.focus();
	}
	else
	{
		document.form.txtOtherIdType.value="";
		document.form.cmbIdType.focus();
	}

}

function otheridtypenull(sel)
{
	option=document.form.cmbIdType.options[document.form.cmbIdType.selectedIndex].text;
	txt=option;
	option1=document.form.txtOtherIdType.value;
	txt1=option1;

	if(txt == 'Other' && txt1 == "Enter Other ID type here")
	{
		if(!confirm('Are you sure NOT to enter other ID type?'))
		{
			document.form.txtOtherIdType.select();
			document.form.txtOtherIdType.focus();
		}
		else
		{
			document.form.txtOtherIdType.value="";
			document.form.txtNumber.focus();
		}
	}
	else
	{

	}

}

function chequenumber(sel)
{
	option=document.form.txtChequePayee.value;
	txt=option;

	if(txt == "")
	{

	}
	else
	{
		message='Enter Check Number here';
		document.form.txtErAmountRecieptNo.value=message;
		document.form.txtErAmountRecieptNo.select();
		document.form.txtErAmountRecieptNo.focus();
	}

}

function checkvalue(sel)
{
	option=document.form.txtErAmountRecieptNo.value;
	txt1=option;

	option=document.form.txtChequePayee.value;
	txt2=option;

	if(txt1 == "Enter Check Number here" && txt2 != "")
	{
		message='Enter Check Number here';
		document.form.txtErAmountRecieptNo.value=message;
		document.form.txtErAmountRecieptNo.select();
		document.form.txtErAmountRecieptNo.focus();
	}
	else
	{
		//document.form.txtErAmountRecieptNo.value="";
	}
}

function checkpayee(sel)
{
	option=document.form.txtErAmountRecieptNo.value;
	txt1=option;

	option=document.form.txtChequePayee.value;
	txt2=option;

	if(txt2 == "")
	{
		message='Please Enter Check Payee and Number';
		document.form.txtErAmountRecieptNo.value="";

		document.form.txtChequePayee.focus();
		alert(message);
		document.form.txtChequePayee.focus();
		return false;
	}
}

function checknull(sel)
{
	option=document.form.txtFortnightlyPayments.value;
	txt1=option;


	if(txt1 == null )
	{
		message="0"
		document.form.txtFortnightlyPayments.value=message;
	}
	else
	{
		document.form.txtFortnightlyPayments.value="";

	}

}
</script>

<?
	if ($_GET['ClientID'] && $_GET['VisitID'] && !isset($_GET['Delete']))
	{
		//echo"Visit ID : ".$visitID."";
		$ClientID = $_GET['ClientID'];
		$VisitID = $_GET['VisitID'];
		$arrClient = getArrayFromTable("er_Client","client_id",$ClientID);

		$resultVisit = getselectedVisitDetails($VisitID);

		$visit_record = mysql_num_rows($resultVisit);

		echo"<h1>Edit Visit</h1>";
		echo "All required fields are marked with by the <img src=\"images/required.gif\" alt=\"required field\" /> icon.<hr>";

		if ($visit_record>0)
		{
			while ($rowVisit = mysql_fetch_array($resultVisit))
			{
				echo "<form name=form action=\"?page=submit_visit_modify\" method=\"post\">";
				echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">";


				echo "<tr>" .
				"<td width=\"17%\">Site Visited:</td>" .
				"<td width=\"32%\">";
				$query="SELECT * FROM er_site ORDER BY site_name" ;
				$results=r_db($query);
				while ($row=mysql_fetch_array($results))
				{
					echo "<label for=\"$row[1]\" style=\"padding-right:10px;\">$row[1]<input type=\"radio\" name=\"cmbSite\" value=\"$row[0]\" id=\"$row[1]\" ";
						if ($rowVisit['site_visited_id'] == $row[0]) {
							echo "CHECKED";
						}
					echo "/></label>";

				}
			  echo "</td>";



				$DbDOB=explode("-",$rowVisit['visit_date']);

					$dayDOB=$DbDOB[2];

					$monthDOB=$DbDOB[1];

					$yearDOB=$DbDOB[0];

					$DOB=$dayDOB."/".$monthDOB."/".$yearDOB;


				echo  '<td width="17%">Visit Date</td>
					  <td width="32%">
						<input 	type=text 
								name=txtVisitDate 
								value=' . $DOB . '
								size=10 
								maxlength=10>&nbsp;<img alt="Date Picker" onclick="new CalendarDateSelect( $(this).previous(), {year_range:10} );" src="./images/calendar.gif" style="border:0px; cursor:pointer;" />
						<br>DD/MM/YYYY or empty
					  </td>';


				//generateTextBox("Visit Date", "text", "txtVisitDate", $DOB);
			  	echo "</tr>";

			  	foreach ($arrClient as $client)
			  	{
			  		echo "<td>Surname:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
			  		echo "<td>$client->surname</td>";
			  		echo "<td>Given&nbsp;Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
			  		echo "<td>$client->givenName</td>";
			  		echo "<tr>";
			  	}
				echo "<tr>";

				echo "<input type=\"hidden\" name=\"txtCentreLinkAmount\" value=\"0\">";
				echo "</tr>";
				print "<input type=\"hidden\" name=\"visitID\" value=\"$VisitID\">";
				echo "<input type=\"hidden\" name=\"txtVisitRecordedDate\">";

				echo "<tr>";
				echo "<td>Address:</td>";
				echo "<td><input type=\"text\" name=\"txtCurrentAddress\" value=\"".$rowVisit['address']."\"></td>";
				echo "<td>Suburb:</td>";
				echo "<td><input type=\"text\" name=\"txtCurrentSuburb\" value=\"".$rowVisit['suburb']."\"></td>";
				echo "</tr>";

				echo "<tr>";

				$arrStates = array("VIC","NSW","QLD", "ACT","NT", "WA", "SA", "TAS");
				echo "<td>State:&nbsp;&nbsp;&nbsp;</td>";
				echo "<td><select size=\"1\" name=\"txtCurrentState\">";

				foreach ($arrStates as $valueState)
				{
					if($rowVisit['state'] == $valueState)
					{
						echo "<OPTION selected>$valueState</option>";
					}
					else
					{
						echo "<OPTION>$valueState</option>";
					}
				}


				echo  "<td>Post Code:</td>";

				echo "<td><input type=text name=txtCurrentPostCode value=".$rowVisit['postcode']."></td>";
				echo "</tr>";


				echo "<tr>";


				echo  "<td>Phone Number</td>";

				echo "<td><input type=text name=txtPhone value=".$rowVisit['phone_no']." maxlength=\"30\"></td>";
				echo "<td>Mobile Number:</td>";
    		echo "<td><input type=text name=txtMobile value=".$rowVisit['mobile_no']." maxlength=\"30\"></td>";
				echo "</tr>";

				$DbDOB=explode("-",$client->dob);

					$dayDOB=$DbDOB[2];

					$monthDOB=$DbDOB[1];

					$yearDOB=$DbDOB[0];

					$DOB1=$dayDOB."/".$monthDOB."/".$yearDOB;


				echo "<td >Date Of Birth</td>";
	    		echo "<td >$DOB1</td>";
if (strtolower($client->gender)=="f")
	$gender = "Female";
else
	$gender = "Male";
	    		echo "<td>Gender: </span></td>";
	    		echo "<td>$gender</td>";
	  			echo "</tr>";

	  			echo "<tr>";

	  			echo "<td>ID Type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
	  			$rowId = getFieldsFromLookUpTable("er_Identification_Type","identification_no",$client->identification_no);
	  			echo "<td>$rowId[1]</td>";
	  			echo "<td>Other (specify):</td>";
	  			echo "<tr>";
	  			echo "<td>ID Number:</td>";
	  			echo "<td>$client->id_reference_no</td>";

	  			echo "<tr>";
				echo  "<td>Adults Assisted: <img src=\"images/required.gif\" alt=\"required field\" /></td>";
				echo "<td><input type=text name=txtAdults value=\"".$rowVisit['no_adults_assistted']."\"></td>";
  			echo  "<td>Children Assisted: <img src=\"images/required.gif\" alt=\"required field\" /></td>";
				echo "<td><input type=text name=txtChildren value=\"".$rowVisit['no_children_assistted']."\"></td>";
				echo "</tr>";

				echo "</table>";

				echo "<hr>";

				echo "<h3><u>Assistance Provided</h3></u>";
				echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">\n";


				echo "<tr>
		    	<td>ER Given:</td>";
				if ($rowVisit['er_given']=="N")
				{
					echo "<td><input type=\"radio\" value=\"Y\" name=\"optErGiven\" onfocus=\"enableassistance('form','payment[]')\">Yes&nbsp;&nbsp;&nbsp;";
					echo "<input type=\"radio\" value=\"N\" name=\"optErGiven\" checked onfocus=\"disableassistance('form','payment[]')\">No</td>";
				}
				else
				{
					echo "<td><input type=\"radio\" value=\"Y\" name=\"optErGiven\" checked onfocus=\"enableassistance('form','payment[]')\">Yes &nbsp;&nbsp;&nbsp;";
					echo "<input type=\"radio\" value=\"N\" name=\"optErGiven\" onfocus=\"disableassistance('form','payment[]')\" >No</td>";
				}
				echo "</tr>";
		    //=================================PAYMENTS ON VISIT======================

				echo "<tr>";
				if ($rowVisit['referred_internal']=="Yes")
				{
					echo "<td>I referred this client internally</td>";
					echo "<td><input type=\"radio\" value=\"Yes\" name=\"referred_internal\" checked>Yes&nbsp;&nbsp;&nbsp;";
					echo "<input type=\"radio\" value=\"No\" name=\"referred_internal\">No<br /></td>";
					echo "<tr></tr>";
				}
				else
				{
					echo "<td>I referred this client internally</td>";
					echo "<td><input type=\"radio\" value=\"Yes\" name=\"referred_internal\">Yes&nbsp;&nbsp;&nbsp;";
					echo "<input type=\"radio\" value=\"No\" name=\"referred_internal\" checked>No<br /></td>";
					echo "<tr></tr>";
				}

				if ($rowVisit['referred_external']=="Yes")
				{
					echo "<tr>";
					echo "<td>I referred this client externally</td>";
					echo "<td><input type=\"radio\" value=\"Yes\" name=\"referred_external\" checked>Yes&nbsp;&nbsp;&nbsp;";
					echo "<input type=\"radio\" value=\"No\" name=\"referred_external\">No<br /></td>";
				}
				else
				{
					echo "<td>I referred this client externally</td>";
					echo "<td><input type=\"radio\" value=\"Yes\" name=\"referred_external\">Yes&nbsp;&nbsp;&nbsp;";
					echo "<input type=\"radio\" value=\"No\" name=\"referred_external\" checked>No<br /></td>";
					echo "<tr></tr>";
				}


		    $clientPayments = getArrayFromTable("er_Payment_On_Visit","visit_id",$VisitID);
		    $payments = get_labels_addvisit("er_payment");
		    foreach ($payments as $value)
			{
		    	echo "<tr>\n";
		    	echo "<td>$value->payment_type:</td>";
		    	foreach($clientPayments as $value1) {
					if ($value1->payment_id == $value->payment_id) {
						if (!empty($value1->payment_amount)) {
							$amount = number_format(round($value1->payment_amount,2),2);
						}
						else $amount = "0.00";
					}
				}
				reset($clientPayments);
		    	echo "<td><input type=\"textbox\" name=\"payment$value->payment_id\" value=\"$amount\" size=\"6\" maxlength=\"6\" onblur=\"this.value = convertcurrentcy1(this.value);\">";
		    	if($value->payment_type=="Other")
		    	{
		    		echo "<tr>\n";
		    		echo "<td >Other Payment Type:</td>";
		    		echo "<td ><input type=\"text\" name=\"txtOtherPaymentType\" size=\"20\" maxlength=\"30\"  value=\"".$rowVisit['other_payment_type']."\"></td>";
		    		echo "<tr>\n";
		    		echo "<td >Extra Food Parcels:</td>";
		    		echo "<td ><input type=\"textbox\" name=\"extraFoodParcels\" value=\"".$rowVisit['extra_food_parcels']."\" size=\"6\" maxlength=\"6\" onblur=\"this.value = convertcurrentcy1(this.value);\">";
		    		echo "</td>";
		    	}
		    }
		    echo "<tr>";
		    echo "<td>Cheque Payee (for cheques only):</td>";
		    echo "<td><input type=\"textbox\" name=\"txtChequePayee\" maxlength=\"20\" value=\"".$rowVisit['cheque_payee']."\" onchange=\"remove_XS_whitespace(this);chequenumber(this)\" onblur=\"remove_XS_whitespace(this)\"></td>";
		    echo "<td>Cheque No:</td>";
		    echo "<td><input type=\"textbox\" name=\"txtErAmountRecieptNo\" maxlength=\"20\" size=\"20\" value=\"".$rowVisit['er_amount_receipt_no']."\" onchange=\"return checkban(this)\" onblur=\"checkvalue(this)\" ><br /><span style=\"font-size:8pt\">Numbers only</span></td>";
		    echo "</tr>";
		    echo "<tr>";
		    echo "<td>Reason for Cheque Payment:</td>";
		    echo "<td><input type=\"textbox\" name=\"txtReasonChequePayment\" maxlength=\"30\" value=\"".$rowVisit['reason_cheque_payment']."\" onblur=\"remove_XS_whitespace(this)\"  onchange=\"return checkpayee(this)\" >";
		    echo "</tr>";
				echo "</table>\n";

				echo "<hr>";

				//==================Income Source======================
				echo "<h3>Sources of Household Incomes</h3>";

				echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">\n";
				$client_income = getArrayFromTable("er_client_income", "visit_id",$VisitID);
				$countClientIncome = count($client_income);

				$incomes_source = get_labels("er_income_source");

				$html_incomes = make_html($incomes_source, $client_income, 3, 400, "incomes[]", "amount[]","whenDue[]");

				if($countClientIncome==3)
				echo "$html_incomes";
				else
				{
					$loops =  3-$countClientIncome;
					for ($count=1;$count<=$loops;$count++)
					{

							echo "<tr>";
							echo "<td>";
							echo "<select name=incomes[]>";
							echo "<option>Select Client Income</option>";
							$query="SELECT * FROM er_income_source ORDER BY income_type" ;

							$results=r_db($query);

							while ($row=mysql_fetch_array($results))

							{
								if ($row[1]!="Other" && $row[1]!="Select Client Income")
								echo "<option>$row[1]</option>";

							}
							echo "<option>Other</option>";
							echo "</select>";
							echo "</td>";
							echo  "<td><input type=\"text\" name=\"amount[]\" value=\"\"></td>\n";
							echo "<td><input type=\"text\" 
										name=\"whenDue[]\" 
										value=\"\"
										size=\"10\" 
										maxlength=\"10\">&nbsp;<img alt=\"Date Picker\" onclick=\"new CalendarDateSelect( $(this).previous(), {year_range:10} );\" src=\"images/calendar.gif\" style=\"border:0px; cursor:pointer;\" />
									<br>DD/MM/YYYY or empty
								  </td>";
							echo "</tr>";

					}
				}


				echo  "<td>Other (specify)</td>";

				echo "<td><input type=text name=txtOtherIncomeSourceType value=\"".$rowVisit['other_income_source']."\"></td>";
				echo "</tr>";
				echo "</table>";

				echo "<hr>";

				echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">";

				echo "<tr>";
				echo "<td width=\"29%\">Income Status:</td>";
				echo "<td><select name=\"cmbIncomeStatus\">";
				populateSelectedDropDownListBoxes("er_income_status",1, $rowVisit['income_status_type'], "income_status_type");
				echo "</select>";
				echo "</td>";

				echo  "<td>Other (specify):</td>";

				echo "<td><input type=text name=txtOtherIncomeStatusType value=\"".$rowVisit['other_income_status']."\"></td>";
				echo "</tr>";

				echo "<tr>";
				echo "<td>Housing Type:</td>";
				echo "<td><select name=\"cmbHousingType\" >";
				populateSelectedDropDownListBoxes("er_housing_type",1, $rowVisit['housing_type'],"housing_type" );
				echo "</select>";
				echo "</td>";


				echo  "<td>Other (specify):</td>";

				echo "<td><input type=text name=txtOtherHousingType value=\"".$rowVisit['other_housing_type']."\"></td>";
				echo "</tr>";

				echo "<tr>";

				echo  "<td>Rent paid per fortnight:</td>";

				echo "<td><input type=text name=txtFortnightlyPayments value=\"".$rowVisit['rent_paid_pf']."\"></td>";
				echo "</tr>";

				echo "<tr>";
				echo "<td>Client Referred By:</td>";
				echo "<td><select name=\"cmbAgency\">";
				populateSelectedDropDownListBoxes("er_agency",1, $rowVisit['agency_name'], "agency_name");
				echo "</select>";
				echo "</td>";
				echo "</tr>";

				echo "</table>";
				//================Emergency Relief=========================

				$reliefs = get_labels("er_Emergency_Relief");

				$checkedEr = getArrayFromTable("er_Relief_On_Visit","visit_id",$VisitID);
				$html_reliefs = make_er_checkbox_html($reliefs, 4, 400, "emergencyReliefs[]", $checkedEr);

				echo "<hr><h3>Reasons for Seeking Assistance</h3>";

				echo "$html_reliefs";

				echo  "<td>Other (specify):</td>";

				echo "<td><input type=text name=txtOtherEr value=\"".$rowVisit['other_ER']."\"></td>";

				echo "</tr>";
				echo "</table>";



				echo "<br>";
				echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">";

				$actions = get_labels("er_action_taken");

				$checkedAction = getArrayFromTable("er_action_on_visit","visit_id",$VisitID);
				$html_reliefs = make_actions_checkbox_html($actions, 3, 400, "actionTaken[]", $checkedAction);

				echo "<hr><h3>Action Taken Associated with E.R. (e.g. referred to other services and agencies)</h3>";

				echo "$html_reliefs";

				echo "</tr>";
				echo "</table>";

				echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">\n";

				echo "<tr><td>&nbsp;</td></tr>";


				echo "<tr><td>Client Signature:</td>";
				if ($rowVisit['client_signature']=="N")
				{
					echo "<td><input type=\"radio\" value=\"Y\" name=\"optClientSignature\">Yes";
					echo "<input type=\"radio\" value=\"N\" name=\"optClientSignature\" checked>No";
				}
				else
				{
					echo "<td><input type=\"radio\" value=\"Y\" name=\"optClientSignature\" checked>Yes";
					echo "<input type=\"radio\" value=\"N\" name=\"optClientSignature\">No";
				}
				echo "</tr>";

				echo "<tr>";
				echo "<td>Interviewer: <img src=\"images/required.gif\" alt=\"required field\" /></td>";
				echo "<td><input type=\"text\" value=\"".$rowVisit['interviewer']."\" name=\"txtInterviewer\" >";
				echo "</tr>";
				echo "</table>";

?>
				<hr>
				<p align="center"><input type=button value="Update" style="width:200px"  onclick="verify();" name="btnSaveForm">
				</form>
<?
			}
		}
		else {
			echo "No visits found for this client!";
		}

	}// END OF EDIT VISIT

	elseif ($_GET['Delete'] == "yes" && $_GET['VisitID'] && $_GET['ClientID'])
	{
		$ClientID = $_GET['ClientID'];
		$VisitID = $_GET['VisitID'];

		$query = "SELECT * FROM er_visit WHERE visit_id=$VisitID";

		$sql = r_db($query);

		$result = mysql_num_rows($sql);

		if($result > 0)
		{
			deleteRecordWithPK("er_visit","visit_id",$VisitID);
			deleteRecordWithPK("er_client_income","visit_id",$VisitID);
			deleteRecordWithPK("er_payment_on_visit","visit_id",$VisitID);
			deleteRecordWithPK("er_relief_on_visit","visit_id",$VisitID);
			deleteRecordWithPK("er_page2","visit_id",$VisitID);

			$query="SELECT * FROM er_visit where visit_id='$VisitID'";

			echo "Visit has been successfully deleted";

			$results=r_db($query);


			while ($row=mysql_fetch_array($results))
			{
				deleteRecordWithPK("er_client_income","visit_id",$row[0]);
			}
		}


	}//END OF DELETE VISIT

?>
